/*
Disclaimer of Warranty: THE PACKAGE IS PROVIDED
BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS'
AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT
ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF
THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


(c) Copyright 2013 Edward Principe
All Rights Reserved

*/
#include <Windows.h>
#include <tchar.h>
#include <iostream>
#include <syntaxex.h>
#include <smtptr.h>
#include "parseall.h"

using namespace std;

void PrintReport(SmtPtr<ParseAll>& parse, SyntaxErr err);

//////////////////////////////////////////////////////////////
// RunTest: Runs tests
//////////////////////////////////////////////////////////////
extern "C" __declspec(dllexport) void RunTest()
{
	SyntaxErr err; // Error code
	SmtPtr<SyntaxEx> se; // Error class
	SmtPtr<ParseAll> parse; // Parser class

	// Initialize
	parse->InitDelim(L"!@#$%^&*()_+-={}|[]\\:;<>,.?/");
	parse->InitComment(L'\'');


	parse->InitBuffer(L"\"My name\"+\" Edward Principe\" + 582/34^54*9+\"My string\" ' My comment");

	// Parse loop
	while (true)
	{
		// Parse next word
		err = parse->Next();

		// At end?
		if (parse->IsEnd())
		{
			wcout << L"*** At End ****" << endl;
			break;
		}

		// Print Report
		PrintReport(parse, err);
	}

	 // Parse backwards
	while (true)
	{
		// Parse previous word
		err = parse->Prev();

		// At the beginning
		if (parse->IsBegin())
		{
			wcout << L"*** At Beginning ****" << endl;
			break;
		}

		// Print Report
		PrintReport(parse, err);
	}

}

/////////////////////////////////////////////////////////////////////
// PrintReport: Prints a report of current item
/////////////////////////////////////////////////////////////////////
void PrintReport(SmtPtr<ParseAll>& parse, SyntaxErr err)
{
	// Print Report
	SmtPtr<SyntaxEx> se;

	se->PutErr(err);

	wcout << L"***" << endl;
	wcout << L"Word: " << parse->GetWord() << endl;
	wcout << L"Error: " << se->MakeMsg() << endl;
	wcout << L"IsString: " << parse->IsString() << endl;
	wcout << endl;
	wcout << L"IsBegin: " << parse->IsBegin() << endl;
	wcout << L"IsEnd: " << parse->IsEnd() << endl;
}
